from datetime import date, time, timedelta
from typing import Optional

from pydantic import BaseModel
from tortoise.contrib.pydantic import pydantic_model_creator, pydantic_queryset_creator

from app.models.schedule import Break, BreakReason, BreakStatus, Shift, ShiftStatus
from app.schemas.doctors import DoctorSchema, ModalitySchema

# class BreakCreateSchema(BaseModel):
#     doctor_id: int
#     start_inclusive: date
#     end_inclusive: date
#     reason: Optional[BreakReason]
#     status: Optional[BreakStatus]


# class BreakStatusUpdateSchema(BaseModel):
#     status: BreakStatus


# BreakSchema = pydantic_model_creator(Break, name="Break")
# BreakListSchema = pydantic_queryset_creator(Break)


class ShiftCreateSchema(BaseModel):
    doctor_id: int
    date: date
    start_time: time
    end_time: time
    break_time: timedelta
    status: Optional[ShiftStatus] = ShiftStatus.REQUESTED


class ShiftStatusUpdateSchema(BaseModel):
    start_time: Optional[time]
    end_time: Optional[time]
    break_time: Optional[timedelta]
    status: Optional[ShiftStatus] = ShiftStatus.REQUESTED


class ShiftSchema(BaseModel):
    id: int
    doctor: DoctorSchema
    date: date
    start_time: time
    end_time: time
    break_time: timedelta
    status: ShiftStatus


############ TimeSheet ##############

# [
#   {
#     user_id: 1,
#     modality: {},
#     additional_modalities: [],
#     ставка: 50,
#     total_first_half_month: 72,
#     total_second_half_month: 30,
#     working_days: [
#       {
#         date: '01.06.2024',
#         from: '8:00',
#         to: '20:00',
#         timeout: 30,
#         worked: 12
#       },
#       {
#         date: '01.06.2024',
#         from: '8:00',
#         to: '20:00',
#         timeout: 30,
#         worked: 12
#       },
#       {
#         date: '01.06.2024',
#         from: '8:00',
#         to: '20:00',
#         timeout: 30,
#         worked: 12
#       },
#       {
#         date: '01.06.2024',
#         from: '8:00',
#         to: '20:00',
#         timeout: 30,
#         worked: 12
#       }
#     ]
#   }
# ]


class TimeSheetRowWorkingDay(BaseModel):
    date: date
    from_: time
    to: time
    timeout: int
    worked: int


class TimeSheetRow(BaseModel):
    user_id: int
    modality: ModalitySchema
    additional_modalities: list[ModalitySchema]
    rate: int
    total_first_half_month: int
    total_second_half_month: int
    working_days: list[TimeSheetRowWorkingDay]
